<template>
  <div>
    <el-card class="box-card" v-if="item">
      <el-row>
        <el-col :span="3">类型/关系</el-col>
        <el-col :span="3">一级(人)</el-col>
        <el-col :span="3">购买数量(张)</el-col>
        <el-col :span="3">二级(人)</el-col>
        <el-col :span="3">购买数量(张)</el-col>
      </el-row>
      <el-row>
        <el-col :span="3">线上</el-col>
        <el-col :span="3">{{item.level1.upCount}}</el-col>
        <el-col :span="3">{{item.level1.upSum}}</el-col>
        <el-col :span="3">{{item.level2.upCount}}</el-col>
        <el-col :span="3">{{item.level2.upSum}}</el-col>
      </el-row>
      <el-row>
        <el-col :span="3">线下</el-col>
        <el-col :span="3">{{item.level1.downCount}}</el-col>
        <el-col :span="3">{{item.level1.downSum}}</el-col>
        <el-col :span="3">{{item.level2.downCount}}</el-col>
        <el-col :span="3">{{item.level2.downSum}}</el-col>
      </el-row>
      <el-row>
        <el-col :span="3">汇总</el-col>
        <el-col :span="3">{{item.level1.downCount+item.level1.upCount}}</el-col>
        <el-col :span="3">{{item.level1.upSum+item.level1.downSum}}</el-col>
        <el-col :span="3">{{item.level2.downCount+item.level2.upCount}}</el-col>
        <el-col :span="3">{{item.level2.upSum+item.level2.downSum}}</el-col>
      </el-row>
    </el-card>

    <el-divider></el-divider>

    <el-table

      :data="postList"
      style="width: 100%"
      row-key="id"
      v-loading="loading"
      border
      lazy
      :tree-props="{hasChildren: 'hasChildren'}"
      :load="load"
    >
      <el-table-column label="用户编号" align="center" prop="idNo"/>
      <el-table-column label="用户昵称" align="center" prop="nickname"/>
      <el-table-column label="角色" align="center" prop="role" :formatter="roleFormat"/>
      <el-table-column label="手机号码" align="center" prop="mobile"/>
      <el-table-column label="线上购买" align="center" prop="upSum"/>
      <el-table-column label="线下购买" align="center" prop="downSum"/>
      <el-table-column label="线上/线下总数" align="center">
        <template slot-scope="scope">
          <span>{{scope.row.downSum+scope.row.upSum}}</span>
        </template>
      </el-table-column>
      <el-table-column label="下级购买" align="center" prop="level2Buy"/>


    </el-table>
  </div>
</template>

<script>
  import {teamList, teamUser} from "@/api/maker/team";

  export default {
    props: {
      row: {
        type: Object,
        require: true
      },
      roleOptions: {
        type: Array,
        require: true
      }
    },
    data() {
      return {
        queryParams: {
          userId: undefined,
          level: 1
        },
        postList: [],
        loading: false,
        item: undefined
      }
    },
    created() {
      console.log(this.row);
      this.queryParams.userId = this.row.userId;
      this.getList();
    },
    methods: {
      getList() {
        this.loading = true;
        teamList(this.queryParams).then(response => {
          this.postList = response.rows;
          this.total = response.total;
          this.loading = false;
        });

        teamUser({userId: this.row.userId}).then(response => {
          console.log(response);
          this.item=response.data;
        });
      },
      load(tree, treeNode, resolve) {
        teamList({userId: tree.userId, level: 2}).then(response => {
          console.log(response);
          resolve(response.rows);
        });

      },
      roleFormat(row, column) {
        return this.selectDictLabel(this.roleOptions, row.role);
      }
    }
  }
</script>

<style scoped>
  .box-card .el-row {
    margin: 10px 0;
    font-size: 14px;
  }
</style>
